<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% 
String path=request.getContextPath(); 
String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href="<%=basePath%>">
<title>方案审核</title>

<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
</head>

<script type="text/javascript">
	var formFlag = false;
	var checkOrBack = "";
	$(document).ready(function() {
		isReadyIframe();
		
		//编辑成功返回该页面的提示
		<%if(null != request.getAttribute("flag")){
			if("edit".equals(request.getAttribute("flag").toString())){%>	
				$.message("success","修改成功");
			<%}
			if("add".equals(request.getAttribute("flag").toString())){%>
				$.message("success","添加成功");
			<%}
		}%>
		
		queryNlifePlan(1);
	});
	
	function isReadyIframe(){
		var iframe = $(window.parent.document).find("#iframe").length;
		if(iframe==0){
			window.location.href="<%=basePath%>index.jsp";
		}
	}
	
	//点击“选择(合作伙伴)”
	function openChannelPageDiv(){
		queryChannelInfo(1);
	}
	
	//为查询合作伙伴 拼接参数
	function queryChannelInfo(pageIndex){
		var channelCode = $.trim($('#channelCode_choose').val());
		var channelName = $.trim($('#channelName_choose').val());
		
		loadChannelInfo({current:pageIndex,size:8,channelCode:channelCode,channelName:channelName});
	}
	
	//加载合作伙伴
	function loadChannelInfo(param){
		$.openLoading();
		$.ajax({
			url : "<%=path%>/nlifePlanConfig/queryChannelInfoPageByCriteria?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:param,
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page))return;
	
				var radioObj ="<input class='input_fxk' name='radioChannelInfo' type='radio' value=''>";
				var fieldNames = "channelCode,channelName";
				var tableContent = creatTable1(fieldNames,page,radioObj);
				var tableObj = $("#channelInfoTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage2(param.current,6,page.maxPage,"42");
				var pageDIV = $("#channelInfoPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
				$('#channelInfoDiv').OpenDiv();
				
				bindradio();
			}
		});
	}  
	
	//点击“确定”按钮，选择合作伙伴
	function chooseChannelInfo(){
		var selected = $("input[name='radioChannelInfo']:checked");
		if(selected.length==0){
			$.message("error", "请选择一个合作伙伴");
			return;
		}
		var channelCode = selected.parent().parent().children(" td:eq(1)").html();
		$('#partnerNo').val(channelCode);
		
		closeChannelInfoDiv();
	}
	
	//关闭 选择合作伙伴 弹出层
	function closeChannelInfoDiv(){
		$("#channelInfoDiv").CloseDiv();	
		
		$('#channelCode_choose').val("");
		$('#channelName_choose').val("");
	}
	
	//为查询投保方案 拼接参数
	function queryNlifePlan(pageIndex){
		var partnerNo = $.trim($('#partnerNo').val());
		var planNo = $.trim($('#planNo').val());
		var planName = $.trim($('#planName').val());
		var prodCode=$.trim($('#prodCode').val());
		
		loadNlifePlan({current:pageIndex,size:10,prodCode:prodCode,partnerNo:partnerNo,planNo:planNo,planName:planName});
	}
	
	//点击"重置"方案查询条件
	function resetQueryNlifePlanCriteria(){
		$("#queryNlifePlanCriteriaTable input[type!='button']").val("");
	}
	
	//加载投保方案
	function loadNlifePlan(param){
		$.openLoading();
		$.ajax({
				url : "<%=path%>/nlifePlanCheck/queryUnApproveNlifePlanPageByCriteria?"+new Date().getTime(),
				type : 'POST',
				async : true,
				dataType:'json',
				data:param,
				success : function(page) {
					$.closeLoading();
					if($.validate(page))return;
					
					var firstbutton ="<input class='input_fxk' name='checkPlan' type='checkbox' value=''>";
					var lastbutton = "<a href='javascript:void(0)' onClick='editNlifePlan(this);return false'>编辑</a>";
					//&nbsp;<a href='javascript:void(0)' onClick='delNlifePlan(this);return false'>删除</a>
					var tableContent = creatTable1("PLAN_NO,PLAN_NAME,PROD_CODE,PROD_NAME,PARTNER_NO,CHANNEL_NAME",page,firstbutton,lastbutton);
					
					var tableObj = $("#nlifePlanTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					var strPage = creatChannelPage(param.current,6,page.maxPage,"49");
					var pageDIV = $("#nlifePlanPageDIV");
					pageDIV[0].innerHTML="";
					
					pageDIV.append(strPage);
					
					bindradio();//点击单选按钮，该行高亮显示
				}
			});
	}
	
	
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='radioChannelInfo']").click(function(){
			$("input[name='radioChannelInfo']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
	}
	//编辑(方案),跳转至 编辑方案 页面
	function editNlifePlan(nlifePlan){
		var delTr = $(nlifePlan).parent('td').parent('tr')[0];
		var planNo = delTr.childNodes[1].innerHTML;
		window.location.href='<%=path%>/nlifePlanCheck/toCheckNlifePlan?planNo='+planNo;
	}
	function closeOpinionDiv(){
		$("#checkOpinionDiv").CloseDiv();
		$("#checkOpinion").val("");
		checkOrBack = "";
	}
	// 打开审核意见说明弹窗
	function openCheckDiv(obj) {
		checkOrBack = obj.attr("id");
		var checkedBox = $("input[name='checkPlan']:checked");
		if (checkedBox.length == 0) {
			$.message("error", "请选择方案")
			return;
		}
		var checkPlanNoList = "";
		checkedBox.each(function () {
			var planNo = $.trim($(this).parent().parent().children("td:eq(1)").html());
			var planName = $.trim($(this).parent().parent().children("td:eq(2)").html());
			checkPlanNoList += planNo + " ";
		})
		$("#checkOpinionDiv").OpenDiv();
		$("#checkPlanList").html(checkPlanNoList);
	}
	// 批量审核
	function batchCheckOrBack() {
		var flag = checkOrBack;
		if (checkOrBack != "batchCheck" && checkOrBack != "batchBack"){
			$.message("error", "系统错误请联系管理员")
			return;
		}
		var checkOpinion =$.trim($('#checkOpinion').val());
		if(checkOpinion.length > 1000){
			$.message("error", "审核意见超过最大字数");
			return;
		}
		if(checkOpinion.length <= 0) {
			$.message("error", "审核意见不能为空");
			return;
		}
		var planList = [];
		var checkedBox = $("input[name='checkPlan']:checked");
		checkedBox.each(function () {
			var planNo = $.trim($(this).parent().parent().children("td:eq(1)").html());
			planList.push(planNo);
		})
		if (planList.length === 0) {
			$.message("error", "请选择方案");
			return;
		}
		closeOpinionDiv();
		var plans = planList.toString();
		$.openLoading();
		$.ajax({
			url: "<%=path%>/nlifePlanCheck/batchCheckPlan",
			type: 'POST',
			async: true,
			data: {planList: plans, checkOpinion: checkOpinion, flag: flag},
			dataType: 'json',
			success: function (data) {
				$.closeLoading();
				if ($.validate(data)) return;
				queryNlifePlan(1);
			}
		})
	}

	// 批量删除
	function batchDeletePlan() {
		var planList = [];
		var choosePlans = "";
		$("input[name='checkPlan']:checked").each(function () {
			var planNo = $.trim($(this).parent().parent().children("td:eq(1)").html());
			var partnerNo = $.trim($(this).parent().parent().children("td:eq(5)").html());
			var nlifePlan = new Object();
			nlifePlan.planNo = planNo;
			nlifePlan.partnerNo = partnerNo;
			planList.push(nlifePlan);
			choosePlans += " " + planNo + " ";
		})
		if (planList.length === 0) {
			$.message("error", "请选择方案");
			return;
		}
		$.dialog({
			type: "warn",
			content: "您确定要删除" + choosePlans + "方案吗？",
			onOk: function() {
				$.openLoading();
				$.ajax({
					url: "<%=path%>/nlifePlanCheck/batchDeleteNlifePlan?" + new Date().getTime(),
					type: "POST",
					async: true,
					data: JSON.stringify(planList),
					dataType: "json",
					contentType: "application/json",
					success: function (data) {
						$.closeLoading();
						if ($.validate(data)) return;
						queryNlifePlan(1);
					}
				});
			}
		});
	}

</script>
<body>
	<div class="current">
          <table class="current_table_1">
             <tbody>
               <tr class="f2">
                 <td><img src="./images/current_1.jpg"></td>
                 <td class="current_table_1_td">
                   <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                     <span style=" color:#136bab; ">新意健险产品管理
                     <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>方案审核
                 </span>
                 </td>
                 <td><img src="./images/current_3.jpg"></td>
             </tr>
          </tbody>
        </table>
     </div>
	
	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table" id="queryNlifePlanCriteriaTable">
					<tr height="30px">
						<td width="32%" height="30">
							<div style="display: inline-block;">
								合作伙伴代码：
								<input name="txt3"  id="partnerNo" value="" readonly="readonly" style="background: #ccc;" class="input_text">
								<input type="button"  class="input_button_1" id="openChannelPageDivBtn" value="选择" onClick="openChannelPageDiv()"/>
							</div>
						</td>
						<td width="23%" height="30">产品编号：
							&nbsp;&nbsp;<input name="txt3" id="prodCode" value="" class="input_text" />
						</td>
						</tr>
						<tr height="30px">
						<td width="23%" height="30">投保方案号：
							&nbsp;<input name="txt3" id="planNo" value="" class="input_text" />
						</td>
						<td width="30%" height="30">投保方案名称：
							<input name="txt3" id="planName" value=""  class="input_text" />
						</td>
						<td width="15%" height="30">
							<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryNlifePlan(1)"/>&nbsp;
							<input type="button" value="重置" onClick="resetQueryNlifePlanCriteria()" class="input_button_1" />							
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="100%" height="30">
							<input type="button" class="input_button_2" id="batchCheck" value="批量通过" onClick="openCheckDiv($(this))">&nbsp;
							<input type="button" class="input_button_2" id="batchBack" value="批量退回" onClick="openCheckDiv($(this))">&nbsp;
							<input type="button"  class="input_button_2" id="deleteBtn" value="批量删除" onClick="batchDeletePlan()"/>&nbsp;
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table id="nlifePlanTable"  class="content_table_1">
					<thead>
						<tr class="f1">
		                  <th style="width:3%">选择</th>
		                  <th style="width:5%">投保方案号</th>
		                  <th style="width:9%">投保方案名称</th>
		                  <th style="width:6%">产品编号</th>
		                  <th style="width:8%">产品名称</th>
		                  <th style="width:6%">合作伙伴代码</th>
		                  <th style="width:8%">合作伙伴名称</th>
		                  <th style="width:4%">操作</th>
		              	</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				<div id="nlifePlanPageDIV"  class="page"></div>
			</td>
		</tr>
	</table>
	<%-- 审核意见弹框 --%>
	<div id="checkOpinionDiv" style="display:none;width:80%;overflow-y: auto;">
		<div style='width:100%;height:20px;line-heighe:20px;background-color:#A4BDE3'>
			<table class="table_title">
				<tr>
					<td width="70px"></td>
					<td width="100%" id=""></td>
					<td width="40px" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeOpinionDiv()"/></td>
				</tr>
			</table>
		</div>
		<div>
			<table class="search_table"  align="center">
				<tr>
					<td style="text-align: center; background-color: #fff;" >批量审核说明信息</td>
				</tr>
			</table>
		</div>
		<div>
			<table class="search_table"  align="center">
				<tr>
					<td style="text-align: center; background-color: #fff;">已选方案：<span  id="checkPlanList"></span></td>
				</tr>
			</table>
		</div>
		<div style="text-align: center">

		</div>
		<div>
			<table class="search_table"  align="center">
				<tr>
					<td style="text-align: center; background-color: #fff;">审核意见：</td>
					<td style="background-color: #fff;">
						<textarea name="checkOpinion" id="checkOpinion" rows="5" class="textarea_1" style="resize:none;" cols=""></textarea>
						<span style="color: red; line-height: 50px">*</span>
					</td>
				</tr>
			</table>
		</div>
		<div align="center">
			<input class="input_button_3" name="" type="button" onclick="batchCheckOrBack()" value="确定">&nbsp;&nbsp;
			<input class="input_button_3" name="" type="button" onclick="closeOpinionDiv()"  value="取消">
		</div>
	</div>
	<!-- 选择 合作伙伴 div-->
  	<div id="channelInfoDiv" style="display:none;width:90%;text-align: center;">
		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeChannelInfoDiv()"/></td>
					</tr>
				</table>
		</div>
		<table class="table_02" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
								合作伙伴代码：<input name="txt3"  id="channelCode_choose" class="input_text" />&nbsp;&nbsp;
								合作伙伴名称：<input name="txt3" id="channelName_choose" class="input_text" />&nbsp;&nbsp;
								<input type="button"  class="input_button_1" value="查询" onClick="queryChannelInfo(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="channelInfoTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="channelInfoPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" value="确定" onclick="chooseChannelInfo()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeChannelInfoDiv()" class="input_button_3"/>
		</div>
	</div>	
</body>
</html>